//
//  WHMainViewController.swift
//  WHSinaWeiBo
//
//  Created by 王寒 on 16/4/6.
//  Copyright © 2016年 wanghan. All rights reserved.
//

import UIKit

class WHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let mainTabBar = WHMainTabarView()
        setValue(mainTabBar, forKey: "tabBar")

        
        
        //添加控制器
        addChildViewControllers()

    }
    
    
    private func addChildViewControllers(){
        addChildViewControllerfunc(WHHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewControllerfunc(WHMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewControllerfunc(WHDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewControllerfunc(WHProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    
    private func addChildViewControllerfunc(vc: UIViewController,title: String,imageName: String){
        vc.navigationItem.title = title
        vc.tabBarItem.title = title
        vc.tabBarItem.image = UIImage(named: imageName);
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
        let nav = WHBaseViewController(rootViewController: vc)
        addChildViewController(nav)
    }

}

